package www.ym.com.service.impl;

import ch.qos.logback.classic.spi.EventArgUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import www.ym.com.common.CustomException;
import www.ym.com.common.R;
import www.ym.com.entity.SetmealDish;
import www.ym.com.entity.User;
import www.ym.com.mapper.SetmealDishMapper;
import www.ym.com.mapper.UserMapper;
import www.ym.com.service.SetmealDishService;
import www.ym.com.service.UserService;
import www.ym.com.utils.Md5Utils;

import java.util.List;
import java.util.UUID;

@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserService userService;

    @Autowired
    private UserMapper userMapper;


    /**
     * 分页查询
     *
     * @param jsonObject
     * @return
     */

    public Page<User> pageUser(JSONObject jsonObject) {

        //当前页数
        Long pageNum = Long.valueOf(String.valueOf(jsonObject.get("pageNum")));
        //当前页有多少条数据
        Long pageSize = Long.valueOf(String.valueOf(jsonObject.get("user")));
        //用户名
        String username = String.valueOf(jsonObject.get("username"));

        //筛选条件
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(User::getUsername, username);

        Page<User> userPage = userMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
//        System.out.println("数据为：" + userPage.getRecords());
//        System.out.println("总数为：" + userPage.getTotal() + ",总页数为：" + urf.getPages());
//        System.out.println("当前页为：" + userPage.getCurrent() + ",每页限制：" + urf.getSize());
        return userPage;
    }


}
